package com.xnx3.wangmarket.plugin.innerAccount.init;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import com.xnx3.j2ee.Global;
import com.xnx3.j2ee.func.Log;
import com.xnx3.j2ee.service.SqlService;
import com.xnx3.wangmarket.plugin.innerAccount.entity.Department;


/**
 * 从数据库中，加载超级管理员定义的关键字
 * 系统启动时跟随启动
 * @author 管雷鸣
 */
@Component
public class GenerateDepartmentListByDataBase {
	@Resource
	private SqlService sqlService;
	
	public GenerateDepartmentListByDataBase() {
		new Thread(new Runnable() {
			public void run() {
				Log.info("start wait load plugin innerAccount department list ...");
				load();
			}
		}).start();
	}
	
	public void load(){
		//等待数据库加载完毕
		while(Global.get("ALLOW_USER_REG") == null){
			try {
				Thread.sleep(1000);	//延迟1秒
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		
		//数据库基本配置参数加载完毕后，将部门机构列表生成js缓存
		List<Department> list = sqlService.findAll(Department.class);
		new com.xnx3.wangmarket.plugin.innerAccount.generateCache.Department().departmentList(list);
		
		Log.info("load plugin innerAccount department list Finish !  "+list.size()+" number");
	}
}
